<template>
  <div></div>
</template>

<script>
import { mapActions } from 'vuex';
import { formatUser } from '@/components/users/format';

export default {
  name: 'direct_sign_in', // 用户已绑定，直接登录
  created() {
    this.autoSignIn();
  },
  methods: {
    ...mapActions({ setCurUser: 'setCurrentUser' }),
    autoSignIn() {
      this.$api.oauth.directSignIn({
        openId: this.$route.query.open_id,
        type: this.$route.query.type,
      }).then((res) => {
        this.setCurUser(formatUser(res.data));
        const redirect = localStorage.getItem('otherSignIn');
        localStorage.removeItem('otherSignIn');
        this.$router.push(redirect || '/');
      }).catch(() => {});
    },
  },
};
</script>

<style></style>
